﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using SmartProject.Data;
using System.Data;

namespace SmartProject.BusinessObjects
{
    public class Attachment : Entity
    {
        private readonly AttachmentReferenceObject _referenceObject;
        private readonly FileType _fileType;

        public Attachment()
        {
            _fileType = new FileType();
            _referenceObject = new AttachmentReferenceObject();

            DataParameter[] dataParameters = new DataParameter[8];
            dataParameters[0] = new DataParameter("AttachmentId", DataType.Integer);
            dataParameters[1] = new DataParameter("OwnerId", DataType.Integer);
            dataParameters[2] = new DataParameter("ReferenceId", DataType.Integer);
            dataParameters[3] = new DataParameter("ReferenceObjectId", DataType.Integer);
            dataParameters[4] = new DataParameter("Filecontent", DataType.Bytes);
            dataParameters[5] = new DataParameter("Filename", 300);
            dataParameters[6] = new DataParameter("FiletypeId", DataType.Integer);
            dataParameters[7] = new DataParameter("Created", DataType.DateTime);
            base.Initialize(dataParameters);
        }

        public override void Load()
        {
            base.Load("smartProject_GetAttachment");
        }

        public override void Save()
        {
            base.Run("smartProject_AddAttachment");
        }

        public override void Update()
        {
            // You cannot update an attachment. Remove and add new if
            // if you need to perform such an action.
        }

        public override void Remove()
        {
            base.Run("smartProject_RemoveAttachment");
        }

        /// <summary>
        /// Gets the types of files supported by SmartProject.
        /// </summary>
        public FileType AttachmentFileType
        {
            get { return _fileType; }
        }

        /// <summary>
        /// Gets the business object that will have attachments associated with them.
        /// </summary>
        public AttachmentReferenceObject ReferenceObject
        {
            get { return _referenceObject; }
        }
    }
}
